package com.swt.testdemo.controller;

import com.swt.testdemo.config.ResponseBean;
import com.swt.testdemo.config.ResponseMessage;
import com.swt.testdemo.form.AddUserForm;
import com.swt.testdemo.form.EditUserForm;
import com.swt.testdemo.form.UserListForm;
import com.swt.testdemo.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author BleethNie
 * @version 1.0
 * @date 2020/11/11 11:02
 **/
@RestController
@RequestMapping("/sys/user")
@Api(tags = "后台管理 -- 用户管理")
@Slf4j
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;


    @ApiOperation("01 创建用户")
    @PostMapping("/create")
    public ResponseEntity<ResponseBean> createUser(AddUserForm form){
        ResponseBean response = sysUserService.createUser(form);
        return ResponseEntity.status(response.getStatus()).body(response);

    }

    @ApiOperation("02 编辑用户")
    @PutMapping("/edit")
    public ResponseEntity<ResponseMessage> editUser(EditUserForm form){
        ResponseMessage response = sysUserService.editUser(form);
        return ResponseEntity.status(response.getStatus()).body(response);

    }


    @ApiOperation("03 删除用户")
    @DeleteMapping("/delete")
    public ResponseEntity<ResponseMessage> deleteUser(Integer userId){
        ResponseMessage response = sysUserService.deleteUser(userId);
        return ResponseEntity.status(response.getStatus()).body(response);

    }

    @ApiOperation(" 04 启用用户")
    @PostMapping("/enable")
    public ResponseEntity<ResponseMessage> enableUser(Integer userId){
        ResponseMessage response = sysUserService.enableUser(userId);
        return ResponseEntity.status(response.getStatus()).body(response);
    }

    @ApiOperation("05 停用用户")
    @PostMapping(value = "/disable")
    public ResponseEntity<ResponseMessage> disableUser(Integer userId){
        ResponseMessage response = sysUserService.disableUser(userId);
        return ResponseEntity.status(response.getStatus()).body(response);
    }


    @ApiOperation("06 重置用户密码")
    @PostMapping(value = "reset-password")
    public ResponseEntity<ResponseMessage> resetUserPassword(Integer userId){
        ResponseMessage response = sysUserService.resetUserPassword(userId);
        return ResponseEntity.status(response.getStatus()).body(response);

    }

    @ApiOperation("07 获取用户列表信息")
    @GetMapping(value = "/list")
    public ResponseEntity<ResponseBean> listUser(UserListForm form){
        ResponseBean response = sysUserService.listUser(form);
        return ResponseEntity.status(response.getStatus()).body(response);
    }


    @ApiOperation("08 获取简单用户列表")
    @GetMapping(value = "/user-map")
    public ResponseEntity<ResponseBean> listUserAsMap(String userFilter,String statusFilter){
        ResponseBean response = sysUserService.listUserAsMap(userFilter, statusFilter);
        return ResponseEntity.status(response.getStatus()).body(response);

    }







}
